package com.zhongwang.mms.module.buy.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.buy.model.ShoppingPlanChangeModel;
import com.zhongwang.mms.module.buy.service.PlanChangeQueryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Description: 采购管理 -> 计划变更查询
 * 查看 -> buy:changequery:view
 * @Author: China.sgl
 * @Date: 2020/4/7 14:42
 */
@SuppressWarnings("ALL")
@Controller
@RequestMapping("/buy/planChangeQuery")
public class PlanChangeQueryController extends BaseController {

    @Autowired
    private PlanChangeQueryService service;

    /**
     * 计划变更查询页面
     *
     * @return 路径
     */
    @GetMapping
    @RequiresPermissions({" buy:changequery:view"})
    public String page(Model model) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        String start = sdf.format(new Date());
        String end = sdf2.format(new Date());
        model.addAttribute("start", start + "-1");
        model.addAttribute("end", end);
        return "buy/planChangeQuery/page";
    }

    /**
     * 计划变更列表数据
     *
     * @param shoppingPlanChangeModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"buy:changequery:view"})
    public JsonResult list(ShoppingPlanChangeModel shoppingPlanChangeModel) {
        startPage();
        List<ShoppingPlanChangeModel> list = service.findPlanChangeByQuery(shoppingPlanChangeModel);
        return jsonResult(list);
    }
}
